<?php
/**
 * Created by PhpStorm.
 * Author: ljz
 * Date: 2023/5/03
 * Time: 16:00
 */

namespace App\frontend\models;


use App\common\models\BaseModel;

/**
 * Class OrderModel
 * @package app\common\models
 */
class OrderModel extends BaseModel
{
    public $table = 'orders';
    public $attributes = ['display_order' => 0];

    /**
     * 定义字段名
     *
     * @return array
     */
    public function atributeNames()
    {
        return ['title' => '商品名称', 'price' => '价格', 'cost_price' => '成本价', 'sku' => '商品属性', 'thumb' => '图片', 'weight' => '重量', 'stock' => '库存',];
    }

    /**
     * 字段规则
     *
     * @return array
     */
    static public function rules()
    {
        return [
            'id'    => 'required | numeric',
            'title' => 'required',
        ];
    }

    /**
     * 字段验证返回错误信息
     *
     * @return array
     */
    static public function message()
    {
        return [
            'id.required'    => 'id不能为空',
            'title.required' => '标题不能为空',
        ];
    }

    public static function getGoodsById($id)
    {
        return static::find($id);
    }

    public static function getGoodsByIds($ids)
    {
        if (!is_array($ids)) {
            return [];
        }
        return self::whereIn('id', $ids)->get();
    }

    public function hasManyParams()
    {
        return $this->hasMany('app\common\models\GoodsParam', 'goods_id', 'id');
    }

}
